home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / a7221v1b.zip / ADI7221 / HP7221.C < prev    next >
C/C++ Source or Header  |  1992-03-12  |  15KB  |  461 lines

  1. /*
  2.    Module:  hp7221.c
  3.    Date:    3/9/92
  4.    Version: 1.0b
  5.    Author:  Dave Lutz
  6.    Email:   lutz@psych.rochester.edu
  7.    Copyright: 1992 University of Rochester, Psychology Dept.
  8.  
  9.    Disclaimer:  This software is distributed free of charge.  As such, it
  10.                 comes with ABSOLUTELY NO WARRANTY.  The user of the software
  11.                 assumes ALL RISKS associated with its use.
  12.  
  13.                 Your rights to modify and/or distribute this software are
  14.                 outlined in the file ADI7221.DOC.
  15.  
  16.    Purpose: This module provides functions for assembling the codes that
  17.             are to be sent to the HP 7221 plotter.  Each function assembles
  18.             a char array of codes that are used to represent the
  19.             desired plotter functions.  The resulting arrays are then
  20.             output via the putarr function that is provided by the
  21.             generic ADI module.
  22.  
  23.    Functions provided:
  24.  
  25.         dev_beginplot
  26.         dev_endplot
  27.         dev_move
  28.         dev_draw
  29.         dev_newpen      (automatic pen selection)
  30.         dev_setspeed
  31.         dev_linetype
  32.         dev_penchange   (pen up for manual pen change)
  33.         dev_abortplot
  34.  
  35.         Note: When a dev_penchange is called, the main driver is expected
  36.         to pause while the operator manually changes the pen.  If this is
  37.         not possible (ie the driver is not a direct feed to the plotter),
  38.         dev_penchange should not be called.
  39.  
  40.    Functions required:
  41.  
  42.         putarr       (output an char array)
  43.         uinttosbn    (unsigned int to Single Byte Number)
  44.         uiptombp     (unsigned int pair to Multiple Byte Pair)
  45. */
  46.  
  47. #include "inout.h"
  48. #include "hpparms.h"
  49. #include "hpcodes.h"
  50. #include "hp7221.h"
  51. #include "retcodes.h"
  52.  
  53. static drawing=FALSE;  /* global used to indicate if we are currently in
  54.                           drawing mode.
  55.                        */
  56.  
  57. /*
  58.    Function: dev_beginplot
  59.    Purpose:  Produces the code used to initialize the plotter for a new
  60.              plot.
  61.  
  62.    Pre: pltfp is a pointer to a PLTFILE that has been opened for writing.
  63.  
  64.    Post: The char array of codes necessary to initialize the plotter is 
  65.          output via putarr().  The array contains the HP_BEGINPLOT code.
  66.          If putarr() returns an error, BADIO is returned.
  67.          Otherwise TRUE is returned.
  68. */
  69.  
  70. int dev_beginplot (pltfp)
  71.    PLTFILE *pltfp;
  72. {
  73.    if (!putarr(pltfp,HPBP_BYTES,HP_BEGINPLOT))
  74.       return (BADIO);
  75.    return (TRUE);
  76. }
  77.  
  78.  
  79.  
  80. /*
  81.    Function: dev_endplot
  82.    Purpose:  Produces the code used to signal the plotter that the current
  83.              plot is complete.
  84.  
  85.    Pre: The global variable 'drawing' indicates whether a draw is currently
  86.         in progess.
  87.         pltfp is a pointer to a PLTFILE that has been opened for writing.
  88.  
  89.    Post: The char array of codes necessary to signal the end of a plot is 
  90.          output via putarr().
  91.          If the global variable 'drawing' is TRUE, it is set FALSE, and the 
  92.          array begins with the HP_END_DRAW code. The array always contains 
  93.          the HP_ENDPLOT code.
  94.          If putarr() returns an error, BADIO is returned.
  95.          Otherwise TRUE is returned.
  96. */
  97.  
  98. int dev_endplot (pltfp)
  99.    PLTFILE *pltfp;
  100. {
  101.    extern drawing;
  102.  
  103.    if (drawing) {
  104.       drawing = FALSE;
  105.       if (!putarr (pltfp,HPED_BYTES,HP_END_DRAW))
  106.          return (BADIO);
  107.    }
  108.    if (!putarr (pltfp,HPEP_BYTES,HP_ENDPLOT))
  109.       return (BADIO);
  110.    return (TRUE);
  111. }
  112.  
  113.  
  114.  
  115. /*
  116.    Function: dev_move
  117.    Purpose:  Produces the code used to cause the plotter to perform a pen 
  118.              up move.
  119.  
  120.    Pre: xcoord contains the X coordinate of the ending location of the move.
  121.         ycoord contains the Y coordinate of the ending location of the move.
  122.         pltfp is a pointer to a PLTFILE that has been opened for writing.
  123.         The global variable 'drawing' indicates if a draw is currently in
  124.         progress.
  125.  
  126.    Post: The char array of codes necessary to perform a pen up move is 
  127.          output via putarr().
  128.          If the global variable 'drawing' is TRUE, it is set FALSE and the
  129.          array begins with the HP_END_DRAW code.  
  130.          The array always includes: the HP_MOVE code, the MBP formatted 
  131.          representation of xcoord and ycoord, and the HP_END_MOVE code.
  132.          If xcoord or ycoord are out of range, BADFMT is returned.
  133.          If putarr returns an error, BADIO is returned.
  134.          Otherwise TRUE is returned.
  135. */
  136.  
  137. int dev_move (xcoord, ycoord, pltfp)
  138.    unsigned xcoord,ycoord;
  139.    PLTFILE *pltfp;
  140. {
  141.    extern drawing;
  142.    char mbp[MAXMBPLEN];
  143.    int cnt;
  144.  
  145.    if (drawing) {
  146.       drawing = FALSE;
  147.       if (!putarr (pltfp,HPED_BYTES,HP_END_DRAW))
  148.          return (BADIO);
  149.    }
  150.    if (!putarr (pltfp,HPM_BYTES,HP_MOVE))
  151.       return (BADIO);
  152.    if (!uiptombp (xcoord, ycoord, mbp, &cnt))
  153.       return (BADFMT);
  154.    if (!putarr (pltfp,cnt,mbp))
  155.       return (BADIO);
  156.    if (!putarr (pltfp,HPEM_BYTES,HP_END_MOVE))
  157.       return (BADIO);
  158.    return (TRUE);
  159. }
  160.  
  161.  
  162.  
  163. /*
  164.    Function: dev_draw
  165.    Purpose:  Produces the code used to cause the plotter to perform a pen
  166.              down draw.
  167.  
  168.    Pre: xcoord contains the X coordinate of the ending location of the draw.
  169.         ycoord contains the Y coordinate of the ending location of the draw.
  170.         pltfp is a pointer to a PLTFILE that has been opened for writing.
  171.         The global variable 'drawing' indicates whether or not a draw is 
  172.         currently in progress.
  173.  
  174.    Post: The char array of codes necessary to perform a pen down draw is 
  175.          output via putarr().
  176.          If the global variable 'drawing' is initially TRUE, the array
  177.          contains only the MBP formatted representation of xcoord and ycoord.
  178.          Otherwise, 'drawing' is set TRUE, and the array contains the
  179.          HP_DRAW code, followed by the MBP formatted representation of
  180.          xcoord and ycoord.
  181.          If xcoord or ycoord are out of range, BADFMT is returned. 
  182.          If putarr() returns an error, BADIO is returned.
  183.          Otherwise TRUE is returned.
  184. */
  185.  
  186. int dev_draw (xcoord, ycoord, pltfp)
  187.    unsigned xcoord, ycoord;
  188.    PLTFILE *pltfp;
  189. {
  190.    extern drawing;
  191.    char mbp[MAXMBPLEN];
  192.    int cnt;
  193.  
  194.    if (!drawing) {
  195.       drawing = TRUE;
  196.       if (!putarr (pltfp,HPD_BYTES,HP_DRAW))
  197.          return (BADIO);
  198.    }
  199.    if (!uiptombp (xcoord, ycoord, mbp, &cnt))
  200.       return (BADFMT);
  201.    if (!putarr (pltfp,cnt,mbp))
  202.       return (BADIO);
  203.    return (TRUE);
  204. }
  205.  
  206.  
  207.  
  208. /*
  209.    Function: dev_newpen
  210.    Purpose:  Produces the code used to cause the plotter to automatically
  211.              select a new pen.
  212.  
  213.    Pre: pennum contains the number of the pen to be selected.
  214.         pltfp is a pointer to a PLTFILE that has been opened for writing.
  215.         The global variable 'drawing' indicates whether a draw is currently
  216.         in progress.
  217.  
  218.    Post: The char array of codes necessary to perform an automatic pen 
  219.          select is output via putarr().
  220.          If the global variable 'drawing' is TRUE, it is set FALSE and the
  221.          array begins with the HP_END_DRAW code.  
  222.          The array always includes the HP_NEWPEN code followed by the SBN
  223.          formatted representation of pennum.
  224.          If pennum is out of range, BADFMT is returned. 
  225.          If putarr() returns an error, BADIO is returned.
  226.          Otherwise TRUE is returned.
  227. */
  228.  
  229. int dev_newpen (pennum, pltfp)
  230.    unsigned pennum;
  231.    PLTFILE *pltfp;
  232. {
  233.    extern drawing;
  234.    char sbn;
  235.  
  236.    if (drawing) {
  237.       drawing = FALSE;
  238.       if (!putarr (pltfp,HPED_BYTES,HP_END_DRAW))
  239.          return (BADIO);
  240.    }
  241.    if (!putarr (pltfp,HPNP_BYTES,HP_NEWPEN))
  242.       return (BADIO);
  243.    if (!uinttosbn(pennum,&sbn))
  244.       return (BADFMT);
  245.    if (!putarr (pltfp,1,&sbn))
  246.       return (BADIO);
  247.    return (TRUE);
  248. }
  249.  
  250.  
  251.  
  252. /*
  253.    Function: dev_setspeed
  254.    Purpose:  Produces the code used to cause the plotter to select a new
  255.              pen speed.
  256.  
  257.    Pre: speed contains the code for the new speed.
  258.         pltfp is a pointer to a PLTFILE that has been opened for writing.
  259.         The global variable 'drawing' indicates whether a draw is currently
  260.         in progress.
  261.  
  262.    Post: The char array of codes necessary to cause the plotter to select 
  263.          a new speed is output via putarr().
  264.          If speed is out of range, BADFMT is returned. 
  265.          If the global variable 'drawing' is TRUE, it is set FALSE and the
  266.          array begins with the HP_END_DRAW code.  
  267.          The array always includes the HP_SETSPEED code followed by the SBN
  268.          fomatted representation of speed.
  269.          If putarr() returns an error, BADIO is returned.
  270.          Otherwise TRUE is returned.
  271. */
  272.  
  273. int dev_setspeed (speed, pltfp)
  274.    unsigned speed;
  275.    PLTFILE *pltfp;
  276. {
  277.    extern drawing;
  278.    char sbn;
  279.  
  280.    if (speed > HP_MAXSPEED)
  281.       return (BADFMT);
  282.  
  283.    if (drawing) {
  284.       drawing = FALSE;
  285.       if (!putarr (pltfp,HPED_BYTES,HP_END_DRAW))
  286.          return (BADIO);
  287.    }
  288.    if (!putarr (pltfp,HPSS_BYTES,HP_SETSPEED))
  289.       return (BADIO);
  290.    if (!uinttosbn(speed,&sbn))
  291.       return (BADFMT);
  292.    if (!putarr (pltfp,1,&sbn))
  293.       return (BADIO);
  294.    return (TRUE);
  295. }
  296.  
  297.  
  298.  
  299. /*
  300.    Function: dev_linetype
  301.    Purpose:  Produces the code needed to cause the plotter to beging using a
  302.              different line type for subesequent draw commands.
  303.  
  304.              Currently supported line types are:
  305.  
  306.                 (0)  ----------------------------------- (solid)
  307.                 (1)  -- -- -- -- -- -- -- -- -- -- -- -- (dashed)
  308.                 (2)  - - - - - - - - - - - - - - - - - - (hidden)
  309.                 (3)  ---- - ---- - ---- - ---- - ---- -  (center)
  310.                 (4)  ----- - - ----- - - ----- - - ----- (phantom)
  311.                 (5)  ................................... (dot)
  312.                 (6)  -- . -- . -- . -- . -- . -- . -- .  (dashdot)
  313.                 (7)  -- -- . -- -- . -- -- . -- -- . --  (border)
  314.                 (8)  -- .. -- .. -- .. -- .. -- .. -- .. (divide)
  315.         
  316.    Pre: linecode contains the code for the desired line type.
  317.         pltfp is a pointer to a PLTFILE that has been opened for writing.
  318.         The global variable 'drawing' indicates whether a draw is currently
  319.         in progress.
  320.  
  321.    Post: The char array of codes necessary to cause the plotter to begin 
  322.          using a different line type is output via putarr().
  323.          If linecode is out of range, BADFMT is returned. 
  324.          If the global variable 'drawing' is TRUE, it is set FALSE and the
  325.          array begins with the HP_END_DRAW code.
  326.          The array always contains the HP_LINETYPE code followed by the
  327.          SBN and MBN representations of the code required to set the desired 
  328.          line type.
  329.          If putarr() returns an error, BADIO is returned.
  330.          Otherwise TRUE is returned.
  331.  
  332.          If the module is compiled with VARIABLE_DASHES defined, patterns
  333.          in the lines will be varied so that an integral number of patterns
  334.          will be included in each line segment.  If VARIABLE_DASHES is not
  335.          defined, fixed length patterns will be used without regard for
  336.          the completeness of each pattern. (ie short line segments may not
  337.          include a complete pattern)
  338. */
  339.  
  340. int dev_linetype (linecode, pltfp)
  341.    unsigned linecode;
  342.    PLTFILE *pltfp;
  343. {
  344.    extern drawing;
  345.    char *codestr;
  346.    int codelen;
  347.  
  348.    switch (linecode) {
  349.       case 0:
  350.          codestr=LT_SOLID;
  351.          codelen=LTS_BYTES;
  352.          break;
  353.       case 1:
  354.          codestr=LT_DASHED;
  355.          codelen=LTDA_BYTES;
  356.          break;
  357.       case 2:
  358.          codestr=LT_HIDDEN;
  359.          codelen=LTH_BYTES;
  360.          break;
  361.       case 3:
  362.          codestr=LT_CENTER;
  363.          codelen=LTC_BYTES;
  364.          break;
  365.       case 4:
  366.          codestr=LT_PHANTOM;
  367.          codelen=LTP_BYTES;
  368.          break;
  369.       case 5:
  370.          codestr=LT_DOT;
  371.          codelen=LTDO_BYTES;
  372.          break;
  373.       case 6:
  374.          codestr=LT_DASHDOT;
  375.          codelen=LTDD_BYTES;
  376.          break;
  377.       case 7:
  378.          codestr=LT_BORDER;
  379.          codelen=LTB_BYTES;
  380.          break;
  381.       case 8:
  382.          codestr=LT_DIVIDE;
  383.          codelen=LTDI_BYTES;
  384.          break;
  385.       default:
  386.          return (BADFMT);
  387.          break;
  388.    }
  389.  
  390.    if (drawing) {
  391.       drawing = FALSE;
  392.       if (!putarr (pltfp,HPED_BYTES,HP_END_DRAW))
  393.          return (BADIO);
  394.    }
  395.    if (!putarr(pltfp,HPLT_BYTES,HP_LINETYPE))
  396.       return (BADIO);
  397.    if (!putarr (pltfp,codelen,codestr))
  398.       return (BADIO);
  399.    return (TRUE);
  400. }
  401.  
  402.  
  403.  
  404. /*
  405.    Function: dev_penchange
  406.    Purpose:  Produces the code needed to raise the pen so that the main
  407.              program can pause and allow the operator to manually change
  408.              pens.
  409.  
  410.    Pre: pltfp is a pointer to a PLTFILE that has been opened for writing.
  411.         The global variable 'drawing' indicates whether a draw is currently
  412.         in progress.
  413.  
  414.    Post: The char array of codes needed to cause the plotter to raise the 
  415.          pen is output via putarr().
  416.          If the global variable 'drawing' is TRUE, it is set FALSE and the
  417.          array begins with the HP_END_DRAW code.  
  418.          The array always contains the HP_PENCHANGE code.
  419.          If putarr() returns an error, BADIO is returned.
  420.          Otherwise, TRUE is returned.
  421. */
  422.  
  423. int dev_penchange (pltfp)
  424.    PLTFILE *pltfp;
  425. {
  426.    extern drawing;
  427.  
  428.    if (drawing) {
  429.       drawing = FALSE;
  430.       if (!putarr (pltfp,HPED_BYTES,HP_END_DRAW))
  431.          return (BADIO);
  432.    }
  433.    if (!putarr (pltfp,HPPC_BYTES,HP_PENCHANGE))
  434.       return (BADIO);
  435.    return (TRUE);
  436. }
  437.  
  438.  
  439.  
  440. /*
  441.    Function: dev_abortplot
  442.    Purpose:  Produces the code needed to cause the plotter to abort all
  443.              actions related to the current plot.
  444.  
  445.    Pre: pltfp is a pointer to a PLTFILE that has been opened for writing.
  446.  
  447.    Post: The char array of codes needed to cause the plotter to abort the 
  448.          current plot is output via putarr().
  449.          The array contains the HP_ABORTPLOT code.
  450.          If putarr() returns an error, BADIO is returned.
  451.          Otherwise, TRUE is returned.
  452. */
  453.  
  454. int dev_abortplot (pltfp)
  455.    PLTFILE *pltfp;
  456. {
  457.    if (!putarr(pltfp,HPAP_BYTES,HP_ABORTPLOT))
  458.       return (BADIO);
  459.    return (TRUE);
  460. }
  461.